/*
 *	INFO	the file implement the simple ip route table with hash
 *		add ,delete ,find ,cout the item in the route table
 *
 *	Author:	mark <mark199312@gmail.com>
 *
 */

#include<stdio.h>
#include<stdlib.h>
#include"ip_table.h"
#include"log.h"
#include"use_hash.h"

/*
 * is to add key into a hash table;
 */

void add_hash(struct fib **head,struct fib *p)
{
	struct fib *temp;

	HASH_FIND(hh,*head,p,sizeof(record_key_t),temp);

	if(temp!=NULL)
	{
		return;
	}
	
	HASH_ADD(hh,*head,key,sizeof(record_key_t),p);
}	

/*
 * is to find a specific packet by key
 */

void struct sockaddr_in * find_hash(struct fib * head,record_key_t *p)
{
	struct fib *temp;
	HASH_FIND(hh,head,p,sizeof(record_key_t),temp);

	if(temp==NULL)
	{
		return NULL;
	}
	else
	{
		return temp->node;
	}
}

/*
 * is to delete a specific packet by key
 */

void delete_hash(struct fib **head,record_key_t *p)
{
	struct fib *temp;

	HASH_FIND(hh,*head,p,sizeof(record_key_t),temp);

	HASH_DEL(*head,temp);

	free(temp);
}

/*
 * is for count hash size
 */

int count_hash(struct fib *head)
{
	int num=0;
	num=HASH_COUNT(head);
	return num;
}

/*
 * is the tool to print the fib
 */

void print_fib(struct fib *head)
{
	struct fib *f;

	for(f=head;f!=NULL;f=f->hh.next)
	{
		log_info("");
	}	
}



